var whereoa = false;
$('.select_cpntainer .active').each(function(){
	var html = $(this).find('a').html();
	var val = $(this).attr('val');
	if($(this).hasClass('brand_liselect')&&val!=''){
		whereoa=true;
		action_this('品牌：'+html);
	}
	if($(this).hasClass('payments_liselect')&&val!=''){
		whereoa=true;
		action_this('首付：'+html);
	}
	if($(this).hasClass('MonthPay_liselect')&&val!=''){
		whereoa=true;
		action_this('月付：'+html);
	}
	if($(this).hasClass('price_liselect')&&val!=''){
		whereoa=true;
		action_this('价格：'+html);
	}
	if($(this).hasClass('Models_liselect')&&val!=''){
		whereoa=true;
		action_this('车型：'+html);
	}
});
function action_this(name) {
	var newdiv = $('<div class="newcar_selected_option"><span> </span><span>x</span></div>');
	newdiv.find('span:first').html(name);
	$('.where_reset').before(newdiv);
}

$('.brand_liselect').click(function(){
	param_url('brand',this);
});

$('.payments_liselect').click(function(){
	param_url('payments',this);
});

$('.MonthPay_liselect').click(function(){
	param_url('MonthPay',this);
});

$('.price_liselect').click(function(){
	param_url('price',this);
});

$('.Models_liselect').click(function(){
	param_url('Models',this);
});

function GetQueryString(name) {
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
}


function param_url(param_k,this_,valn) {
	if(this_){
		var html_b = $(this_).attr('val');
	}else{
		var html_b = valn;
	}
	var url = location.href;
	var arr_url = url.split('?');
	if(arr_url.length==2){
		arr_url[1] = arr_url[1].split('#')[0];
		var brand_p = arr_url[1].split('&');
		var url_r = new Array();
		var ii = 0;
		var istrue = false;
		var param = param_k+'='+html_b;
		for (var i = 0; i < brand_p.length; i++) {
			var brand_l = brand_p[i].split('=');
			if(brand_l[0]==param_k){
				url_r[ii] = param;
				istrue = true;
			}else if(brand_l[0]!=param_k&&brand_l[0]!='page'&&brand_l[0]!='searchkey'){
				url_r[ii] = brand_p[i];
			}
			ii++;
		}
	}else{
		var param = param_k+'='+html_b;
		arr_url[0] = url.split('#')[0];
		var param_url = param;
	}
	
	if(!istrue&&!param_url){
		var param_url = url_r.join('&')+'&'+param;
	}else if(istrue&&!param_url){
		var param_url = url_r.join('&');
	}
	location.href = arr_url[0]+'?'+param_url;
}

function param_url_j(param_k,this_) {
	var html_b = $(this_).attr('val');
	var url = location.href;
	var arr_url = url.split('?');
	arr_url[1] = arr_url[1].split('#')[0];
	var brand_p = arr_url[1].split('&');
	var url_r = new Array();
	var ii = 0;
	var istrue = false;
	for (var i = 0; i < brand_p.length; i++) {
		var brand_l = brand_p[i].split('=');
		if(brand_l[0]!=param_k&&brand_l[0]!='page'){
			url_r[ii] = brand_p[i];
		}
		ii++;
	}
	var param_url = url_r.join('&');
	location.href = arr_url[0]+'?'+param_url;
}

$('.index_header_search_submit').click(function(){
	var searchval = $('.index_header_search_input').val();
	if(searchval){
		param_url('searchkey',false,searchval);
	}
});

$('.index_header_hidden_hot_search_ul li').each(function(){
	var val = $(this).find('a').html();
	if(val){
		$(this).click(function(){
			param_url('searchkey',false,val);
		});
	}
});

$('.orderby_month').click(function(){
	var type = $(this).attr('type_');
	if(type=='asc'){
		param_url('order',false,'MonthPay_1');
	}else if(type=='desc'){
		param_url('order',false,'MonthPay_2');
	}
});

$('.orderby_servicemony').click(function(){
	var type = $(this).attr('type_');
	if(type=='asc'){
		param_url('order',false,'FirstPay_1');
	}else if(type=='desc'){
		param_url('order',false,'FirstPay_2');
	}
});

$('.orderby_default').click(function(){
	param_url('order',false,'preferentialRatio');
});

$(function(){
	if(whereoa){
		$('.where_div').css('display','block');
	}else{
		$('.where_div').css('display','none');
	}
});